package com.yxch.admin.service;

import com.yxch.admin.mapper.CommenMapper;
import com.yxch.admin.model.commen.*;
import com.yxch.admin.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class CommenService {
    @Autowired
    CommenMapper commenMapper;

    public ResultAPI getEnum(String name) {
        List<Commen> commenList = commenMapper.getEnum(name);
//// 转换为 Map<String, String>
//        Map<String, String> enumMap = commenList.stream()
//                .collect(Collectors.toMap(
//                        Commen::getEnum_key,   // Key: enum_key
//                        Commen::getEnum_value  // Value: enum_value
//                ));
        return ResultAPI.success(commenList);
    }

    public ResultAPI getAuditlog(AuditLog auditLog) {
        AuditLog res = commenMapper.getAuditlog(auditLog);
        return ResultAPI.success(res);
    }

    public ResultAPI getEnumList(DictDTO dictDTO) {
        Integer pageNum = dictDTO.getPageNum();
        Integer pageSize = dictDTO.getPageSize();
        Integer startNum = (pageNum - 1) * pageSize;

        dictDTO.setStart(startNum);

        PageResult pageResult = commenMapper.getEnumList(dictDTO);
        return ResultAPI.success(pageResult);
    }

    public ResultAPI AddandUpdateDictEnum(DictDTO dictDTO) {
        if (dictDTO.getEnum_id() != null) {
            commenMapper.updateEnum(dictDTO);
        } else {
            commenMapper.addEnum(dictDTO);
        }
        return ResultAPI.success();
    }

    public ResultAPI DeleteEnumById(List<Integer> ids) {
        commenMapper.DeleteEnumById(ids);
        return ResultAPI.success();
    }

    public ResultAPI getDirections() {
        List<DirectionVO> directionVOs = commenMapper.getDirections();
        return ResultAPI.success(directionVOs);
    }
}
